# 集合set  无重复值
import copy

basket = {"apple", "orange", "apple", "pear", "orange", "banana"}
print(basket)
s1 = set("好好学习天天向上")  # 字符串分解为耽搁元素作为集合元素
print(s1)
s2 = set(("好好", "学习", "天天", "向上"))  # 元组分解为耽搁元素作为集合元素
print(s2)
s3 = set(["好好", "学习", "天天", "向上"])  # 列表分解为耽搁元素作为集合元素
print(s3)

# 添加元素
##添加单个元素
s1.add("4")
print(s1)

##添加多个元素
s2.update(["4", "5", "6"])  # 列表会被分解添加
print(s2)
s3.update("de")  # 字符串会被分解添加
print(s3)

# 删除元素
s1 = set(["Python", "python", "java", "c++", "c#"])
print(s1)
s2 = set(["Python", "python", "java", "c++", "c#"])
print(s2)
s1.remove("c++")  # 没有会报错
print(s1)
s2.discard("c++")  # 没有不会报错
print(s2)
print(s1.pop())  # 随机删除一个
print(s1)

# 交集 &
s1 = set("python")
s2 = set("pycharm")
print(s1 & s2)
print(s1.intersection(s2))

# 并集 |
print(s1 | s2)
print(f"并集{s1.union(s2)}")

# 补集
print(s1 - s2)
print(s1.difference(s2))
print(s2 - s1)
print(s2.difference(s1))

# 差集
print(s1 ^ s2)
print(s1.symmetric_difference(s2))

# 其他操作
s1 = set("好好学习")
s2 = set("天天向上")
s3 = set("好好学习天天向上")

print("好" in s1)
print("好" not in s2)
print(s1.isdisjoint(s2))  # 没有相同元素则为 true
print(s1.issubset(s3))  # s1是否为 s3子集
print(s3.issuperset(s1))  # s1是否为 s3子集

a = set("小楼一夜听春雨")
b = a
c = a.copy()
d = copy.copy(a)
e = copy.deepcopy(a)
print(a)
print(b)
print(c)
print(d)
print(e)
a.add(4)
#a[1][2] = "c"
print(a)
print(b)
print(c)
print(d)
print(e)
